package org.jeecg.modules.param.station.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.bicycle.order.entity.BikeVehicleOrder;
import org.jeecg.modules.bicycle.order.mapper.BikeVehicleOrderMapper;
import org.jeecg.modules.bicycle.vehicle.mapper.BikeVehicleMapper;
import org.jeecg.modules.constant.BikeConstant;
import org.jeecg.modules.dto.station.StationRegisterRsp;
import org.jeecg.modules.param.area.entity.BikeSysArea;
import org.jeecg.modules.param.area.entity.BikeSysUserArea;
import org.jeecg.modules.param.area.mapper.BikeSysAreaMapper;
import org.jeecg.modules.param.area.mapper.BikeSysUserAreaMapper;
import org.jeecg.modules.param.pile.entity.BikePile;
import org.jeecg.modules.param.pile.mapper.BikePileMapper;
import org.jeecg.modules.param.station.entity.BikeStation;
import org.jeecg.modules.param.station.mapper.BikeStationMapper;
import org.jeecg.modules.param.station.service.IBikeStationService;
import org.jeecg.modules.param.station.vo.*;


import org.jeecg.modules.system.upgrade.mapper.BikeUpgradeAppMapper;
import org.jeecg.modules.system.upgrade.mapper.BikeUpgradeAppVersionMapper;
import org.jeecg.modules.utils.ExcelUtils;
import org.jeecg.modules.utils.YueYueNiaoUtils;
import org.jeecg.modules.utils.page.PageInfo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @Description: bike_station
 * @Author: 月月鸟
 * @Date:   2021-05-19
 * @Version: V1.0
 */
@Service
public class BikeStationServiceImpl extends ServiceImpl<BikeStationMapper, BikeStation> implements IBikeStationService {
    @Resource
    private BikeStationMapper bikeStationMapper;
    @Resource
    private BikeVehicleOrderMapper bikeVehicleOrderMapper;
    @Resource
    private BikeSysAreaMapper bikeSysAreaMapper;
    @Resource
    private BikePileMapper bikePileMapper;
    @Resource
    private BikeSysUserAreaMapper bikeSysUserAreaMapper;
    @Resource
    private BikeVehicleMapper bikeVehicleMapper;

    @Resource
    private BikeUpgradeAppVersionMapper bikeUpgradeAppVersionMapper;

    @Resource
    private BikeUpgradeAppMapper bikeUpgradeAppMapper;


    @Override
    public Result<?> stationList(Page<BikeStation> page, BikeStation bikeStation1) {
        //故障状态转换字符
        BikeStation bikeStation = intToHeartStatus(bikeStation1);

        LoginUser principal = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //如果区域无条件，则根据权限展示；
        //获取区域权限
        QueryWrapper<BikeSysUserArea> userAreaQueryWrapper = new QueryWrapper<>();
        userAreaQueryWrapper.eq("user_id", principal.getUsername());
        BikeSysUserArea bikeSysUserArea = bikeSysUserAreaMapper.selectOne(userAreaQueryWrapper);
        if (bikeSysUserArea != null) {
            if (StringUtils.isNotEmpty(bikeSysUserArea.getAreaId())) {
                String[] split = bikeSysUserArea.getAreaId().split(",");
                bikeStation.setAreaUserList(Arrays.asList(split));
                if (StringUtils.isNotEmpty(bikeStation.getAreaId())){
                    bikeStation.setAreaArray(bikeStation.getAreaId().split(","));
                }
                if (StringUtils.isNotEmpty(bikeStation.getIsNewVersion())){
                    String newVersion = bikeUpgradeAppMapper.getNewVersion("100004");
                    bikeStation.setNewVersionCode(newVersion);
                }
                Page<BikeStation> stations = bikeStationMapper.pageList(page, bikeStation);
                PageInfo pageInfo = new PageInfo();
                pageInfo.setSize(stations.getSize());
                pageInfo.setCurrent(stations.getCurrent());
                pageInfo.setTotal(stations.getTotal());
                pageInfo.setRecords(stations.getRecords());
                return Result.OK(pageInfo);
            }else {
                return Result.OK();
            }
        } else {
            return Result.OK();
        }
    }

    private BikeStation intToHeartStatus(BikeStation bikeStation) {
        //车站状态Bit0：电量不足 Bit1：温度过高 Bit2：车桩异常 Bit3：定位信号异常 Bit4-7：保留，默认置0
        if (StringUtils.isNotEmpty(bikeStation.getHeartStatus())) {
            if (bikeStation.getHeartStatus().equals("0")) {
                bikeStation.setHeartStatus("电量不足");
            }
            if (bikeStation.getHeartStatus().equals("1")) {
                bikeStation.setHeartStatus("温度过高");
            }
            if (bikeStation.getHeartStatus().equals("2")) {
                bikeStation.setHeartStatus("车桩异常");
            }
            if (bikeStation.getHeartStatus().equals("3")) {
                bikeStation.setHeartStatus("定位信号异常");
            }
        }
        return bikeStation;
    }

    @Override
    public List<UpSiteRsp> upSiteList(Integer pageNo, Integer pageSize, UpSiteReq upSiteReq) {
        List<UpSiteRsp> upSiteList = bikeStationMapper.upSiteList(upSiteReq);
        for (UpSiteRsp tb : upSiteList){
            if (StringUtils.isNotEmpty(tb.getAppName())){
                tb.setIsNew(BikeConstant.y_n_yes);
            } else {
                tb.setIsNew(BikeConstant.y_n_no);
            }
        }
        return upSiteList;
    }

    @Override
    public List<UpSiteRsp> upSitePileList(Integer pageNo, Integer pageSize, UpSiteReq upSiteReq) {
        List<UpSiteRsp> upSiteList = bikeStationMapper.upSitePileList(upSiteReq);
        for (UpSiteRsp tb : upSiteList){
            if (StringUtils.isNotEmpty(tb.getAppName())){
                tb.setIsNew(BikeConstant.y_n_yes);
            } else {
                tb.setIsNew(BikeConstant.y_n_no);
            }
        }
        return upSiteList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class )
    public Result<?> add(BikeStation bikeStation) {
        QueryWrapper<BikeStation> wrapper = new QueryWrapper<>();
        wrapper.eq("code",bikeStation.getCode());
        List<BikeStation> list = bikeStationMapper.selectList(wrapper);
        if (!list.isEmpty()){
            return Result.error("编号已存在");
        }
        if (StringUtils.isEmpty(bikeStation.getLongitude())){
            bikeStation.setLongitude("0.0");
        }
        if (StringUtils.isEmpty(bikeStation.getLatitude())){
            bikeStation.setLatitude("0.0");
        }
        String uuid=UUID.randomUUID().toString().replace("-", "");
        bikeStation.setId(uuid);
        if (StringUtils.isNotEmpty(bikeStation.getManageName())){
            //获取管理员信息
            SysUserRe sysUser = bikeStationMapper.selectAdmin(bikeStation.getManageName());
            bikeStation.setManageName(sysUser.getRealname());
            //添加权限给网点管理员
            this.addAreaUser(sysUser,uuid);
        }else {
            SysUserRe sysUser = new SysUserRe();
            this.addAreaUser(sysUser,uuid);
        }
        bikeStationMapper.insert(bikeStation);
        //根据数量存入车桩信息
        if (bikeStation.getPileCount()>0){
            for(int i = 1 ; i <=bikeStation.getPileCount();i++){
                BikePile bikePile = new BikePile();
                if (i<10){
                    bikePile.setCode("0"+i);
                }else {
                    bikePile.setCode(""+i);
                }
                bikePile.setCheckCode(YueYueNiaoUtils.getPileCheck(bikeStation.getCode()+bikePile.getCode()));
                bikePile.setStationId(bikeStation.getId());
                bikePile.setLockStatus("1");
                bikePile.setStatus("1");
                bikePileMapper.insert(bikePile);
            }
        }
        return Result.OK();
    }

    private void addAreaUser(SysUserRe sysUser, String stationId) {
        //当前操作人员信息
        LoginUser principal = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //获取添加用户的区域权限
        QueryWrapper<BikeSysUserArea> userAreaQueryWrapper = new QueryWrapper<>();
        userAreaQueryWrapper.eq("user_id", principal.getUsername());
        BikeSysUserArea bikeSysUserArea = bikeSysUserAreaMapper.selectOne(userAreaQueryWrapper);
        if (StringUtils.isNotEmpty(sysUser.getUsername())){
            //获取管理用户的区域权限
            QueryWrapper<BikeSysUserArea> userAreaQueryWrapper2 = new QueryWrapper<>();
            userAreaQueryWrapper2.eq("user_id", sysUser.getUsername());
            BikeSysUserArea bikeSysUserArea2 = bikeSysUserAreaMapper.selectOne(userAreaQueryWrapper2);
            //添加管理用户的权限
            if (bikeSysUserArea2 == null) {
                BikeSysUserArea newUserArea = new BikeSysUserArea();
                newUserArea.setAreaId(stationId);
                newUserArea.setUserId(sysUser.getUsername());
                bikeSysUserAreaMapper.insert(newUserArea);
            } else {
                String a;
                if (StringUtils.isNotEmpty(bikeSysUserArea2.getAreaId())) {
                    a = bikeSysUserArea2.getAreaId() + "," + stationId;
                } else {
                    a = stationId;
                }
                //数组去重
                String[] strings = YueYueNiaoUtils.onlyArrayClear(a.split(","));
                bikeSysUserArea2.setAreaId(YueYueNiaoUtils.arrayToString(strings));
                bikeSysUserAreaMapper.updateById(bikeSysUserArea2);
            }
        }
        //添加添加用户的权限
        if (bikeSysUserArea == null) {
            BikeSysUserArea newUserArea = new BikeSysUserArea();
            newUserArea.setAreaId(stationId);
            newUserArea.setUserId(principal.getUsername());
            bikeSysUserAreaMapper.insert(newUserArea);
        } else {
            String a;
            if (StringUtils.isNotEmpty(bikeSysUserArea.getAreaId())) {
                a = bikeSysUserArea.getAreaId() + "," + stationId;
            } else {
                a = stationId;
            }
            //数组去重
            String[] strings = YueYueNiaoUtils.onlyArrayClear(a.split(","));
            bikeSysUserArea.setAreaId(YueYueNiaoUtils.arrayToString(strings));
            bikeSysUserAreaMapper.updateById(bikeSysUserArea);
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class )
    public Result<?> edit(BikeStation bikeStation) {
        //获取管理员信息
        QueryWrapper<BikeStation> wrapper = new QueryWrapper<>();
        if (bikeStation.getCode()!=null){
            //根据编号判断是否存在
            wrapper.eq("code",bikeStation.getCode());
            wrapper.ne("id",bikeStation.getId());
            List<BikeStation> bikeStations = bikeStationMapper.selectList(wrapper);
            if (!bikeStations.isEmpty()){
                return Result.error("编号已存在!");
            }
        }
        BikeStation data = bikeStationMapper.selectById(bikeStation.getId());
        QueryWrapper<BikePile> pileQueryWrapper = new QueryWrapper<>();
        if (bikeStation.getPileCount()>0){
            Integer selectCount = bikePileMapper.selectCount(new QueryWrapper<BikePile>().eq("station_id", data.getId()));
            BikePile bikePile = bikePileMapper.selectMaxCode(data.getId());
            if (bikePile==null){
                //如果车桩为空
                if (selectCount == 0) {
                    for (int i = 1; i <= bikeStation.getPileCount(); i++) {
                        BikePile bikePile2 = new BikePile();
                        if (i < 10) {
                            bikePile2.setCode("0" + i);
                        } else {
                            bikePile2.setCode("" + i);
                        }
                        bikePile2.setCheckCode(YueYueNiaoUtils.getPileCheck(data.getCode()+bikePile2.getCode()));
                        bikePile2.setStationId(data.getId());
                        bikePile2.setLockStatus("1");
                        bikePile2.setStatus("1");
                        bikePileMapper.insert(bikePile2);
                    }
                    bikeStationMapper.updateById(bikeStation);
                    return Result.OK("编辑成功");
                }else {
                    //如果车桩数 大于  原车桩
                    if (bikeStation.getPileCount()>data.getPileCount()){
                        for (int i = 1; i<=bikeStation.getPileCount(); i++ ){
                            if (i>0){
                                BikePile bp1 = new BikePile();
                                if (i<10){
                                    bp1.setCode("0"+i);
                                }else {
                                    bp1.setCode(""+i);
                                }
                                BikePile bikePile1 = bikePileMapper.selectOne(new QueryWrapper<BikePile>().eq("station_id", data.getId()).eq("code", bp1.getCode()));
                                if (bikePile1==null){
                                    bp1.setCheckCode(YueYueNiaoUtils.getPileCheck(data.getCode()+bp1.getCode()));
                                    bp1.setStationId(bikeStation.getId());
                                    bp1.setLockStatus("1");
                                    bp1.setStatus("1");
                                    bikePileMapper.insert(bp1);
                                }else {
                                    bikePile1.setStatus("1");
                                    bikePileMapper.updateById(bikePile1);
                                }
                            }
                        }
                        bikeStationMapper.updateById(bikeStation);
                        return Result.OK("编辑成功");
                    }
                }
            }
            //如果车桩数 大于  原车桩
            if (bikeStation.getPileCount()>data.getPileCount()){
                for (int i = Integer.parseInt(bikePile.getCode())+1; i<=bikeStation.getPileCount(); i++ ){
                    if (i>0){
                        BikePile bp1 = new BikePile();
                        if (i<10){
                            bp1.setCode("0"+i);
                        }else {
                            bp1.setCode(""+i);
                        }
                        BikePile bikePile1 = bikePileMapper.selectOne(new QueryWrapper<BikePile>().eq("station_id", data.getId()).eq("code", bp1.getCode()));
                        if (bikePile1==null){
                            bp1.setCheckCode(YueYueNiaoUtils.getPileCheck(data.getCode()+bp1.getCode()));
                            bp1.setStationId(bikeStation.getId());
                            bp1.setLockStatus("1");
                            bp1.setStatus("1");
                            bikePileMapper.insert(bp1);
                        }else {
                            bikePile1.setStatus("1");
                            bikePileMapper.updateById(bikePile1);
                        }

                    }
                }
                bikeStationMapper.updateById(bikeStation);
                return Result.OK("编辑成功");
            }
            //如果车桩数 小于  原车桩
            if (bikeStation.getPileCount()<data.getPileCount()){
                for(int j = Integer.parseInt(bikePile.getCode()); j>bikeStation.getPileCount();j--){
                    QueryWrapper<BikePile> wp2 = new QueryWrapper<>();
                    String pileCode = "";
                    if (j<10){
                        pileCode="0"+j;
                    }else {
                        pileCode=""+j;
                    }
                    wp2.eq("station_id",data.getId());
                    wp2.eq("code",pileCode);
                    //bikePileMapper.delete(wp2);
                    BikePile bikePile1 = new BikePile();
                    bikePile1.setStatus("0");
                    bikePileMapper.update(bikePile1,wp2);
                }
                bikeStationMapper.updateById(bikeStation);
                return Result.OK("编辑成功");
            }
        }else {
            pileQueryWrapper.eq("station_id",bikeStation.getId());
            bikePileMapper.update(new BikePile().setStatus("0"),pileQueryWrapper);
            bikeStationMapper.updateById(bikeStation);
            return Result.OK("编辑成功");
        }
        bikeStationMapper.updateById(bikeStation);
        return Result.OK("网点编辑成功","1");
    }

    @Override
    public ModelAndView exportXls(HttpServletRequest request, BikeStation bikeStation) {
        LoginUser principal = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //如果区域无条件，则根据权限展示；
        //获取区域权限
        QueryWrapper<BikeSysUserArea> userAreaQueryWrapper = new QueryWrapper<>();
        userAreaQueryWrapper.eq("user_id", principal.getUsername());
        BikeSysUserArea bikeSysUserArea = bikeSysUserAreaMapper.selectOne(userAreaQueryWrapper);
        if (bikeSysUserArea != null) {
            if (StringUtils.isNotEmpty(bikeSysUserArea.getAreaId())) {
                String[] split = bikeSysUserArea.getAreaId().split(",");
                bikeStation.setAreaUserList(Arrays.asList(split));
                if (StringUtils.isNotEmpty(bikeStation.getAreaId())){
                    bikeStation.setAreaArray(bikeStation.getAreaId().split(","));
                }
                List<BikeStation> bikeStationsList = bikeStationMapper.list(bikeStation);
                return ExcelUtils.exportXls(request,bikeStationsList,BikeStation.class,"网点表");
            }else {
                List<BikeStation> stations = null;
                return  ExcelUtils.exportXls(request,stations,BikeStation.class,"网点表");
            }
        } else {
            List<BikeStation> stations = null;
            return  ExcelUtils.exportXls(request,stations,BikeStation.class,"网点表");
        }
    }

    @Override
    public Result<?> lockStation(StationLock stationLock) {
        String[] ids = stationLock.getId().split(",");
        if (StringUtils.isEmpty(stationLock.getLockCause())){
            stationLock.setLockCause("");
        }
        bikeStationMapper.updateStationLockById(ids,stationLock.getIsLock(),stationLock.getLockCause());
        if (stationLock.getIsLock().equals(BikeConstant.y_n_no)){
            return Result.OK("锁定成功");
        }else {
            return Result.OK("解锁成功");
        }
    }

    @Override
    public Result<?> deleteById(String id) {
        BikeStation bikeStation = bikeStationMapper.selectById(id);
        if (bikeStation.getIsRegister().equals(BikeConstant.y_n_yes)){
            return Result.error("网点已注册，无法删除");
        }else {
            bikeStationMapper.deleteById(id);
            QueryWrapper<BikePile> wrapper = new QueryWrapper<>();
            wrapper.eq("station_id",id);
            bikePileMapper.delete(wrapper);
            return Result.OK("删除成功");
        }

    }

    @Override
    public void addPile(BikeStation bikeStation) {
        QueryWrapper<BikePile> pileQueryWrapper = new QueryWrapper<>();
        if (bikeStation.getPileCount() > 0) {
            BikePile bikePile = bikePileMapper.selectMaxCode(bikeStation.getId());
            Integer pileCount = bikePileMapper.selectCount(new QueryWrapper<BikePile>().eq("station_id", bikeStation.getId()));
            //如果车桩为空
            if (bikePile == null) {
                for (int i = 1; i <= bikeStation.getPileCount(); i++) {
                    BikePile bikePile2 = new BikePile();
                    if (i < 10) {
                        bikePile2.setCode("0" + i);
                    } else {
                        bikePile2.setCode("" + i);
                    }
                    bikePile2.setCheckCode(YueYueNiaoUtils.getPileCheck(bikeStation.getCode()+bikePile2.getCode()));
                    bikePile2.setStationId(bikeStation.getId());
                    bikePile2.setLockStatus("1");
                    bikePile2.setStatus("1");
                    bikePileMapper.insert(bikePile2);
                }
            } else {
                //如果车桩数 大于  原车桩
                if (bikeStation.getPileCount() > pileCount) {
                    for (int i = Integer.parseInt(bikePile.getCode()) + 1; i <= bikeStation.getPileCount(); i++) {
                        if (i > 0) {
                            BikePile bp1 = new BikePile();
                            if (i < 10) {
                                bp1.setCode("0" + i);
                            } else {
                                bp1.setCode("" + i);
                            }
                            bp1.setCheckCode(YueYueNiaoUtils.getPileCheck(bikeStation.getCode()+bp1.getCode()));
                            bp1.setStationId(bikeStation.getId());
                            bp1.setLockStatus("1");
                            bp1.setStatus("1");
                            bikePileMapper.insert(bp1);
                        }
                    }
                }
                //如果车桩数 小于  原车桩
                if (pileCount < bikeStation.getPileCount()) {
                    for (int j = Integer.parseInt(bikePile.getCode()); j > bikeStation.getPileCount(); j--) {
                        QueryWrapper<BikePile> wp2 = new QueryWrapper<>();
                        String pileCode = "";
                        if (j < 10) {
                            pileCode = "0" + j;
                        } else {
                            pileCode = "" + j;
                        }
                        wp2.eq("station_id", bikeStation.getId());
                        wp2.eq("code", pileCode);
                        bikePileMapper.delete(wp2);

                    }
                }
            }
        } else {
            pileQueryWrapper.eq("station_id", bikeStation.getId());
            bikePileMapper.delete(pileQueryWrapper);
        }
    }

    @Override
    public void delPile(List<String> strings) {
        for (String tb : strings){
            QueryWrapper<BikePile> wrapper = new QueryWrapper<>();
            wrapper.eq("station_id",tb);
            bikePileMapper.delete(wrapper);
        }
    }

    @Override
    public String getAreaId(String areaCode) {
        QueryWrapper<BikeSysArea> wrapper = new QueryWrapper<>();
        wrapper.eq("area_code",areaCode);
        BikeSysArea bikeSysArea = bikeSysAreaMapper.selectOne(wrapper);
        if (bikeSysArea!=null){
            return bikeSysArea.getId();
        }
        return null;
    }

    @Override
    public Result<?> clearRegister(String id) {
        BikeStation bikeStation = bikeStationMapper.selectById(id);
        bikeStation.setMacAddress("");
        bikeStation.setIsRegister(BikeConstant.y_n_no);
        updateById(bikeStation);
        return Result.OK("清除成功");
    }


    /**
     *  网点借还车统计
     */
    @Override
    public List<StatisticalRsp> statistical(StatisticalReq statisticalReq, List<BikeStation> bikeStationPage) {
        //获取网点信息
        QueryWrapper<BikeStation> wrapperStation = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(statisticalReq.getStationCode())){
            wrapperStation.eq("code",statisticalReq.getStationCode());
        }
        List<StatisticalRsp> statisticalRspList = new ArrayList<>();
        for (BikeStation bikeStation : bikeStationPage) {
            //bikeStation转存StatisticalRsp
            //网点信息
            StatisticalRsp statisticalRsp = bikeStationGoStatisticalRsp(bikeStation);
            //获取在桩车辆数
            statisticalRsp.setBikeCount(getBikeCount(bikeStation.getId()));
            //获取网点统计后续数据
            statisticalReq.setStationId(bikeStation.getId());
            Map<String, Integer> map = getLowDataByStationId(statisticalReq);
            //获取扫码借车数
            statisticalRsp.setSweepCount(map.get("sweepCount"));
            //获取刷卡借车数
            statisticalRsp.setBrushCount(map.get("brushCount"));
            //获取还车数
            statisticalRsp.setReturnCount(map.get("returnCount"));
            //获取借车数
            statisticalRsp.setLendCount(map.get("lendCount"));
            statisticalRspList.add(statisticalRsp);
        }
        return statisticalRspList;
    }
    /**
     *  网点借还车统计 导出
     */
    @Override
    public ModelAndView exportStatisticalXls(HttpServletRequest request, StatisticalReq statisticalReq, List<BikeStation> list) {
        List<StatisticalRsp> statistical = statistical(statisticalReq, list);
        return  ExcelUtils.exportXls(request,statistical,StatisticalRsp.class,"网点借还车统计表");
    }

    @Override
    public BikeStation getStationByCode(String code) {
        return bikeStationMapper.selectOne(new QueryWrapper<BikeStation>().eq("code",code));
    }

    @Override
    public void addAreaUser(String manageName,String id) {
        if (StringUtils.isNotEmpty(manageName)){
            //获取管理员信息
            SysUserRe sysUser = bikeStationMapper.selectAdmin(manageName);
            //添加权限给网点管理员
            this.addAreaUser(sysUser,id);
        }else {
            SysUserRe sysUser = new SysUserRe();
            this.addAreaUser(sysUser,id);
        }
    }

    @Override
    public List<SysUserRe> getAdminList(SysUserRe sysUserRe) {
        return bikeStationMapper.getAdminList(sysUserRe);

    }


    /**
     *  根据网点id 获取网点统计后续数据
     */
    private Map<String, Integer> getLowDataByStationId( StatisticalReq statisticalReq) {
        Map<String, Integer> map = new HashMap<>();
        //获取扫码借车数
        int sweepCount = 0 ;
        //获取刷卡借车数
        int brushCount = 0 ;
        //获取还车数
        int returnCount ;
        //获取借车数
        int lendCount = 0 ;

        //时间范围内，借出的订单
        List<BikeVehicleOrder> bikeVehicleOrders=bikeVehicleOrderMapper.getBikeOrderLendByStationId(statisticalReq);
        if (!bikeVehicleOrders.isEmpty()){
            lendCount = bikeVehicleOrders.size();
            for (BikeVehicleOrder tb : bikeVehicleOrders){
                if (tb.getUseType().equals("1")){
                    sweepCount++;
                }
                if (tb.getUseType().equals("2")){
                    brushCount++;
                }
            }
        }
        //时间范围内，还车的订单
        returnCount = bikeVehicleOrderMapper.getReturnCountByStationId(statisticalReq);
        //根据网点id查询借车记录
        map.put("sweepCount",sweepCount);
        map.put("brushCount",brushCount);
        map.put("returnCount",returnCount);
        map.put("lendCount",lendCount);
        return map;
    }


    /**
     *  根据网点id 获取在桩车辆数
     */
    private int getBikeCount(String id) {
        return bikeVehicleMapper.getBikeCountByStationId(id);
    }

    /**
     *  bikeStation转存StatisticalRsp
     */
    private StatisticalRsp bikeStationGoStatisticalRsp(BikeStation bikeStation) {
        StatisticalRsp statisticalRsp = new StatisticalRsp();
        if (StringUtils.isNotEmpty(bikeStation.getCode())){
            statisticalRsp.setCode(bikeStation.getCode());
        }
        if (StringUtils.isNotEmpty(bikeStation.getName())){
            statisticalRsp.setName(bikeStation.getName());
        }
        if (StringUtils.isNotEmpty(bikeStation.getName())){
            statisticalRsp.setAddress(bikeStation.getAddress());
        }
        if (StringUtils.isNotEmpty(bikeStation.getName())){
            statisticalRsp.setPileCount(bikeStation.getPileCount());
        }
        return statisticalRsp;
    }


}
